
//气球
var balloonObj = function(){
    this.alive = [];
    this.ctx = ctxMain;
    this.a = [];
    this.x = [];
    this.y = [];
    this.r = [];
    this.color = [];
    this.speedX = [];
    this.speedY = [];
};
balloonObj.prototype.num = 10;
balloonObj.prototype.init = function(){
    for(var i = 0; i < this.num; i++){
        this.alive[i] = false;
    }
    this.yellow = {
        fill: "rgb(255,204,1)",
        stroke: "#e39006"
    };
    this.green = {
        fill: "rgb(1,206,53)",
        stroke: "#006d1e"
    };
    this.red = {
        fill: "rgb(252,0,105)",
        stroke: "#006d1e"
    };
};
balloonObj.prototype.draw = function(){
    for(var i = 0; i < this.num; i++){
        if(this.alive[i]){
            if(this.speedX[i] < -1 || this.speedX[i] > 1){
                this.a[i] *= -1;
            }
            this.speedX[i] -= this.a[i];
            this.x[i] += this.speedX[i];
            this.y[i] -= this.speedY[i];
            utils.drawBalloon(this.ctx, this.x[i], this.y[i], this.r[i], this.color[i].fill, this.color[i].stroke, 0);
            if(this.y[i] < -140 || this.x[i] < -100){
                this.alive[i] = false;
                data.gameOver = true;
            }
        }
    }
};
balloonObj.prototype.born = function(i) {
    this.alive[i] = true;
    this.x[i] = utils.getRandom(50, canWidth);
    this.a[i] = 0.01;
    this.y[i] = canHeight;
    this.r[i] = 40 + 10*Math.random();
    this.speedX[i] = 0.5*Math.random() + 0.5;
    if(Math.random() < 0.5){
        this.speedX[i] = -this.speedX[i];
    }
    this.speedY[i] = 0.5*Math.random() + 2.5;
    var thisRan = Math.random();
    if(thisRan < 0.4){
        this.color[i] = this.yellow;
    }else if(thisRan < 0.8){
        this.color[i] = this.green;
    }else{
        this.color[i] = this.red;

    }
};
balloonObj.prototype.dead = function(i){
    this.alive[i] = false;
};
balloonObj.prototype.boom = function(i){
    //气球死亡
    this.alive[i] = false;

    //碎片产生
    debris.born(this.x[i], this.y[i], this.r[i], this.color[i].fill);

    //红色气球产生爱心
    if(this.color[i].fill == "rgb(252,0,105)"){
        data.double = 2;
        heart.born(balloon.x[i], balloon.y[i], balloon.r[i]);
    }
};
function balloonMonitor(){
    var num = 0, i = 0;
    for(; i < balloon.num; i++){
        if(balloon.alive[i]) num++;
    }
    if(num < 5){
        sentBalloon();
        return null;
    }
}
function sentBalloon(){
    for(var i = 0; i < balloon.num; i++){
        if(!balloon.alive[i]){

            balloon.born(i);
            return;
        }
    }
}